<template>
  <div class="statistics-page">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>数据统计</h1>
      <p>分析档案利用情况，优化管理策略</p>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-cards">
      <!-- 馆藏统计 -->
      <div class="stat-card">
        <div class="card-header">
          <h3><i class="el-icon-folder"></i> 馆藏统计</h3>
        </div>
        <div class="stat-item">
          <div class="stat-label">数字化档案</div>
          <div class="stat-value">1,245,678件</div>
          <div class="stat-bar">
            <div class="stat-progress" style="width: 85%; background-color: #409eff;"></div>
          </div>
        </div>
        <div class="stat-item">
          <div class="stat-label">电子档案</div>
          <div class="stat-value">856,321件</div>
          <div class="stat-bar">
            <div class="stat-progress" style="width: 70%; background-color: #67c23a;"></div>
          </div>
        </div>
        <div class="stat-item">
          <div class="stat-label">音视频</div>
          <div class="stat-value">324,567件</div>
          <div class="stat-bar">
            <div class="stat-progress" style="width: 35%; background-color: #e6a23c;"></div>
          </div>
        </div>
      </div>

      <!-- 利用统计 -->
      <div class="stat-card">
        <div class="card-header">
          <h3><i class="el-icon-data-analysis"></i> 利用统计</h3>
        </div>
        <div class="usage-stats">
          <div class="usage-item">
            <div class="usage-icon">
              <i class="el-icon-user"></i>
            </div>
            <div class="usage-info">
              <div class="usage-label">今日访问</div>
              <div class="usage-value">248</div>
            </div>
          </div>
          <div class="usage-item">
            <div class="usage-icon">
              <i class="el-icon-document"></i>
            </div>
            <div class="usage-info">
              <div class="usage-label">本月查阅</div>
              <div class="usage-value">3,672</div>
            </div>
          </div>
          <div class="usage-item">
            <div class="usage-icon">
              <i class="el-icon-download"></i>
            </div>
            <div class="usage-info">
              <div class="usage-label">档案下载</div>
              <div class="usage-value">1,024</div>
            </div>
          </div>
        </div>
        <div class="chart-placeholder">
          [利用趋势图表区]
        </div>
      </div>

      <!-- 最近活动 -->
      <div class="stat-card">
        <div class="card-header">
          <h3><i class="el-icon-time"></i> 最近活动</h3>
        </div>
        <div class="activity-list">
          <div class="activity-item">
            <div class="activity-icon">
              <i class="el-icon-user"></i>
            </div>
            <div class="activity-content">
              <div class="activity-text">李四 上传了 <strong>2023年度财务报告.pdf</strong></div>
              <div class="activity-time">10分钟前</div>
            </div>
          </div>
          <div class="activity-item">
            <div class="activity-icon">
              <i class="el-icon-folder"></i>
            </div>
            <div class="activity-content">
              <div class="activity-text">王五 更新了 <strong>人事档案分类方案</strong></div>
              <div class="activity-time">1小时前</div>
            </div>
          </div>
          <div class="activity-item">
            <div class="activity-icon">
              <i class="el-icon-download"></i>
            </div>
            <div class="activity-content">
              <div class="activity-text">张三 下载了 <strong>项目合同扫描件.zip</strong></div>
              <div class="activity-time">3小时前</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 分类统计图表 -->
    <div class="chart-section">
      <div class="chart-controls">
        <label>选择分类类型:</label>
        <el-select v-model="selectedChartType" placeholder="按档案名称分类" style="width: 200px;">
          <el-option label="按档案名称分类" value="name"></el-option>
          <el-option label="按文件类型分类" value="type"></el-option>
          <el-option label="按安全级别分类" value="security"></el-option>
        </el-select>
      </div>
      
      <div class="chart-container">
        <h4>档案 名称 分布图</h4>
        <div class="pie-chart-wrapper">
          <div class="pie-chart-container">
            <svg class="pie-chart-svg" viewBox="0 0 300 300">
              <!-- 饼图 -->
              <g transform="translate(150, 150)">
                <!-- 档案A部分 (大部分，约75%) -->
                <path 
                  d="M 0,-100 A 100,100 0 1,1 -70.71,70.71 L 0,0 Z" 
                  fill="#4facfe"
                  class="pie-slice"
                />
                <!-- 档案B部分 (小部分，约25%) -->
                <path 
                  d="M -70.71,70.71 A 100,100 0 0,1 0,-100 L 0,0 Z" 
                  fill="#667eea"
                  class="pie-slice"
                />
              </g>
            </svg>
          </div>
          
          <!-- 图例 -->
          <div class="chart-legend">
            <div class="legend-item">
              <div class="legend-color" style="background-color: #4facfe;"></div>
              <span>档案A</span>
            </div>
            <div class="legend-item">
              <div class="legend-color" style="background-color: #667eea;"></div>
              <span>档案B</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 馆藏明细 -->
    <div class="detail-section">
      <div class="detail-header">
        <h3>馆藏明细</h3>
        <div class="detail-controls">
          <el-input
            v-model="searchKeyword"
            placeholder="搜索字段"
            size="small"
            style="width: 200px; margin-right: 10px;"
          ></el-input>
          <el-date-picker
            v-model="selectedDate"
            type="date"
            placeholder="年-月-日"
            size="small"
            style="width: 150px; margin-right: 10px;"
          ></el-date-picker>
          <el-button type="primary" size="small">查询</el-button>
          <el-button type="success" size="small">新增</el-button>
        </div>
      </div>

      <el-table :data="detailData" style="width: 100%" border>
        <el-table-column prop="id" label="编号" width="80"></el-table-column>
        <el-table-column prop="name" label="名称" min-width="150"></el-table-column>
        <el-table-column prop="date" label="日期" width="120"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="editItem(scope.row)">编辑</el-button>
            <el-button type="text" size="small" style="color: #f56c6c;" @click="deleteItem(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Statistics',
  data() {
    return {
      selectedChartType: 'name',
      searchKeyword: '',
      selectedDate: '',
      detailData: [
        { id: 1, name: '档案A', date: '2025-06-01' },
        { id: 1, name: '档案A', date: '2025-06-01' },
        { id: 1, name: '档案A', date: '2025-06-01' },
        { id: 1, name: '档案A', date: '2025-06-01' },
        { id: 1, name: '档案A', date: '2025-06-01' },
        { id: 2, name: '档案B', date: '2025-06-10' }
      ]
    }
  },
  mounted() {
    // 加载统计数据
  },
  methods: {
    editItem(row) {
      console.log('编辑:', row)
    },
    deleteItem(row) {
      console.log('删除:', row)
    }
  }
}
</script>

<style scoped>
.statistics-page {
  padding: 0;
}

.page-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 40px;
  margin-bottom: 30px;
  border-radius: 8px;
}

.page-header h1 {
  font-size: 28px;
  margin: 0 0 10px 0;
  font-weight: 600;
}

.page-header p {
  font-size: 16px;
  margin: 0;
  opacity: 0.9;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
}

.stat-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  border: 1px solid #e8e8e8;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card-header {
  margin-bottom: 20px;
}

.card-header h3 {
  font-size: 16px;
  margin: 0;
  color: #333;
  display: flex;
  align-items: center;
}

.card-header h3 i {
  margin-right: 8px;
  color: #409eff;
}

.stat-item {
  margin-bottom: 15px;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.stat-bar {
  height: 6px;
  background-color: #f0f0f0;
  border-radius: 3px;
  overflow: hidden;
}

.stat-progress {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.usage-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.usage-item {
  text-align: center;
  flex: 1;
}

.usage-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #f0f9ff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
}

.usage-icon i {
  font-size: 18px;
  color: #409eff;
}

.usage-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.usage-value {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.chart-placeholder {
  height: 120px;
  background-color: #f8f9fa;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 14px;
}

.activity-list {
  max-height: 300px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #f0f9ff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.activity-icon i {
  font-size: 14px;
  color: #409eff;
}

.activity-content {
  flex: 1;
}

.activity-text {
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
}

.activity-time {
  font-size: 12px;
  color: #999;
}

.chart-section {
  margin-top: 20px;
  padding: 20px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-controls {
  margin-bottom: 20px;
}

.chart-controls label {
  font-size: 14px;
  color: #333;
  margin-right: 10px;
}

.chart-container {
  height: 300px;
}

.pie-chart-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
}

.pie-chart-container {
  width: 300px;
  height: 300px;
  margin-bottom: 20px;
}

.pie-chart-svg {
  width: 100%;
  height: 100%;
}

.pie-slice {
  stroke: #fff;
  stroke-width: 2;
  transition: opacity 0.3s ease;
}

.pie-slice:hover {
  opacity: 0.8;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 30px;
}

.legend-item {
  display: flex;
  align-items: center;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  margin-right: 8px;
}

.legend-item span {
  font-size: 14px;
  color: #333;
}

.detail-section {
  margin-top: 20px;
  padding: 20px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.detail-header h3 {
  font-size: 16px;
  margin: 0;
  color: #333;
}

.detail-controls {
  display: flex;
  align-items: center;
}

.detail-controls .el-input {
  margin-right: 10px;
}

.detail-controls .el-date-picker {
  margin-right: 10px;
}

.detail-controls .el-button {
  margin-left: 10px;
}
</style> 